<?php 
namespace Home\Controller;
use Think\Controller;

class TmpController extends Controller
{
	public function index(){return;}

	/**
	 * 满足条件剧集
	 * @param  [type] $userid [description]
	 * @return [type]         [description]
	 */
	public function m1()
	{
		$time1 = microtime();
		$province_id = '17';
		$limit = 50;
		$province_type = '3,4,5';
		// 根据省份获取节目
		$sql = "SELECT a.id id, a.code code, a.cp_code cp_code, a.program_name program_name, a.parent_id parent_id, f.id movie_id, a.status status, a.episode episode, a.duration duration, f.code movie_code, f.type movie_type, f.file_url movie_file_url, f.source_DRM_type movie_source_DRM_type, f.dest_DRM_type movie_dest_DRM_type, f.audio_type movie_audio_type, f.screen_format movie_screen_format, f.closed_captioning movie_closed_captioning, f.video_bitrate movie_video_bitrate, f.create_at movie_create_at, f.update_at movie_update_at, f.program_code movie_program_code, f.program_id movie_program_id, f.parent_cp_code movie_parent_cp_code, f.cp_code movie_cp_code, f.cp_file_url movie_cp_file_url, f.command_id movie_command_id, f.status movie_status, f.download_status movie_download_status, f.is_cached movie_is_cached, f.source movie_source, f.rebuild movie_rebuild, f.filesize movie_file_size,f.filehash movie_file_hash, f.code_rate movie_code_rate FROM t_program AS a JOIN ( SELECT program_id FROM program_province where province_id IN ({$province_id}) ) AS e ON a.parent_id = e.program_id JOIN movie AS f ON f.program_id = a.id JOIN t_program AS g on a.parent_id = g.id WHERE a.status = 0 AND g.status = 0 AND f.status = 0 AND f.code_rate IN ({$province_type}) AND f.id NOT IN (SELECT movie_id FROM t_download WHERE province_id IN ({$province_id})) order by f.id LIMIT ".$limit;
		echo $sql,'<br>';
		$series = M()->query($sql);	
		$time2 = microtime();
		dump($series);
		echo $time2;
		echo '<br>';
		echo $time1;
	}

	public function m2()
	{
		list($mtime1,$time1) = explode(' ',microtime());
		$province_id = '17';
		$limit = 50;
		$province_type = '3,4,5';
		$notid = M('TDownload')->field('movie_id')->where(['province_id'=>['IN',$province_id]])->select();
		$notid = implode(array_column($notid, 'movie_id'),',');
		// 根据省份获取节目
		$sql = "SELECT a.id id, a.code code, a.cp_code cp_code, a.program_name program_name, a.parent_id parent_id, f.id movie_id, a.status status, a.episode episode, a.duration duration, f.code movie_code, f.type movie_type, f.file_url movie_file_url, f.source_DRM_type movie_source_DRM_type, f.dest_DRM_type movie_dest_DRM_type, f.audio_type movie_audio_type, f.screen_format movie_screen_format, f.closed_captioning movie_closed_captioning, f.video_bitrate movie_video_bitrate, f.create_at movie_create_at, f.update_at movie_update_at, f.program_code movie_program_code, f.program_id movie_program_id, f.parent_cp_code movie_parent_cp_code, f.cp_code movie_cp_code, f.cp_file_url movie_cp_file_url, f.command_id movie_command_id, f.status movie_status, f.download_status movie_download_status, f.is_cached movie_is_cached, f.source movie_source, f.rebuild movie_rebuild, f.filesize movie_file_size,f.filehash movie_file_hash, f.code_rate movie_code_rate FROM t_program AS a JOIN ( SELECT program_id FROM program_province where province_id IN ({$province_id}) ) AS e ON a.parent_id = e.program_id JOIN movie AS f ON f.program_id = a.id JOIN t_program AS g on a.parent_id = g.id WHERE a.status = 0 AND g.status = 0 AND f.status = 0 AND f.code_rate IN ({$province_type}) AND f.id NOT IN ($notid) order by f.id LIMIT ".$limit;
		$series = M()->query($sql);	
		list($mtime2,$time2) = explode(' ',microtime());
		dump($series);
		echo ($time2+$mtime2);
		echo '<br>';
		echo ($time1+$mtime1);
		echo '<br>';
		echo ($time2+$mtime2)-($time1+$mtime1);
	}

	public function m3()
	{
		list($mtime1,$time1) = explode(' ',microtime());
		$province_id = '17';
		$limit = 50;
		$province_type = '3';
		$notid = M('TDownload')->field('movie_id')->where(['province_id'=>['IN',$province_id]])->select();
		$notid = implode(array_column($notid, 'movie_id'),',');
		$id = M('ProgramProvince')->field('program_id')->where(['province_id'=>['IN',$province_id]])->select();
		$id = implode(array_column($id, 'program_id'),',');

		// 根据省份获取节目
		$sql = "SELECT a.id id, a.code code, a.cp_code cp_code, a.program_name program_name, a.parent_id parent_id, f.id movie_id, a.status status, a.episode episode, a.duration duration, f.code movie_code, f.type movie_type, f.file_url movie_file_url, f.source_DRM_type movie_source_DRM_type, f.dest_DRM_type movie_dest_DRM_type, f.audio_type movie_audio_type, f.screen_format movie_screen_format, f.closed_captioning movie_closed_captioning, f.video_bitrate movie_video_bitrate, f.create_at movie_create_at, f.update_at movie_update_at, f.program_code movie_program_code, f.program_id movie_program_id, f.parent_cp_code movie_parent_cp_code, f.cp_code movie_cp_code, f.cp_file_url movie_cp_file_url, f.command_id movie_command_id, f.status movie_status, f.download_status movie_download_status, f.is_cached movie_is_cached, f.source movie_source, f.rebuild movie_rebuild, f.filesize movie_file_size,f.filehash movie_file_hash, f.code_rate movie_code_rate FROM t_program AS a JOIN movie AS f ON f.program_id = a.id JOIN t_program AS g on a.parent_id = g.id WHERE a.parent_id IN ($id) AND a.status = 0 AND g.status = 0 AND f.status = 0 AND f.code_rate IN ({$province_type}) AND f.id NOT IN ($notid) order by f.id LIMIT ".$limit;
		$series = M()->query($sql);	
		list($mtime2,$time2) = explode(' ',microtime());
		dump($series);
		echo ($time2+$mtime2);
		echo '<br>';
		echo ($time1+$mtime1);
		echo '<br>';
		echo ($time2+$mtime2)-($time1+$mtime1);
	}

}